package cn.lcsjsxy.yxc.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Enumeration;

@WebServlet(value = "/servlet4")
public class ServletTest4 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //行相关   GET/POST    uri     http/1.1
        System.out.println(req.getMethod());  //获取请求方式
        System.out.println(req.getScheme());  //获取请求协议
        System.out.println(req.getProtocol());  //获取请求协议及版本
        System.out.println(req.getRequestURI());  //获取请求的uri    项目内的资源路径
        System.out.println(req.getRequestURL());  //获取请求的uri    项目内资源的完成的路径
        /*
        * URI   统一资源标识符     interface URI{}      /servletd2/servlet4       资源定位的要求和规范      动物类
        * URL   统一资源定位符     class URL implements URI{}  http://localhost:8080/servletd2/servlet4  一个具体的资源路径        哺乳动物类
        * */
        System.out.println(req.getLocalPort());  //本应用容器的端口号
        System.out.println(req.getServerPort());  //客户端发请求时使用的端口号
        System.out.println(req.getRemotePort());  //客户端软件的端口号
        //头相关   key:value   key:value ... ...
        //根据名字单独获取某个请求头
        String accept=req.getHeader("Accept");
        System.out.println(accept);

        //获取本次请求中所有的请求头的名字
        Enumeration<String> headerNames = req.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String headerName = headerNames.nextElement();
            System.out.println(headerName);
        }
    }
}
